<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/common/commonConfig.jsp"%>

<html>

<head>
	<base href="<%=basePath%>">
	<title>增加用户</title>
	<script src="<%=basePath%>component/layout.js"></script>
    <script src="<%=basePath%>component/toolbar.js"></script>
	<script type="text/javascript" src="<%=basePath%>dwrsystem/interface/userService.js"></script> 
	<script type="text/javascript" src="<%=basePath%>dwrsystem/engine.js"></script>
	<script type="text/javascript" src="<%=basePath%>js/validateJS.js"></script>
	<script type="text/javascript">
	var myUnittree;
	var unitId;
	var dhxLayout = createLayoutNormal('1C',false,true);
	
	function configLayout(){
		var a = dhxLayout.cells('a');
		a.hideHeader();
		a.setText('主页面');
		a.fixSize(true, true);
		createToolbarFromDHXLayoutCell(a,function(toolbar){
		    toolbar.addText("info", 1, "操作:");
		    toolbar.addSeparator("sep1", 2);
		    if(power.getPowerInsert())toolbar.addButton("add", 3, "提交", "save.gif", "save_dis.gif");
		    toolbar.attachEvent("onClick", function(id) {
		    	if(id == 'add'){
		    		validateAdd();
		    	}
		    });
		});
		a.attachObject('dataObj');
	}
	
	$(function (){
		configLayout();
		myUnittree = parent.window.MyTree;
		unitId = '${param.unitId}';
	});
	</script>
</head>

<body><div id="dataObj" style="overflow: auto;">
	<div id="displayDiv" class="formlayout" style="width:100%;height:100%;overflow: auto;">
		<input type="hidden" name="userForm.status" id="userForm.status" value="1"/>
		<table id="addTable" >
			<tr>
				<th>登录账号</th>
				<td>
					<input name="userForm.loginCode" id="userForm.loginCode" maxlength='25'><span class="enterInput">*</span>
				</td>
			</tr>
			<tr>
				<th>登录姓名</th>
				<td>
					<input name="userForm.loginName" id="userForm.loginName" maxlength='25'><span class="enterInput">*</span>
				</td>
			</tr>
			<tr>
				<th>登录密码</th>
				<td>
					<input type="password" name="userForm.loginPassword" id="userForm.loginPassword" maxlength='25'><span class="enterInput">*</span>
				</td>
			</tr>
			<tr>
				<th>备注</th>
				<td>
					<textarea  rows="3" cols="60"  name="userForm.note" id="userForm.note"></textarea>
				</td>
			</tr>
		</table>
	</div></div>
</body>
	
<script type="text/javascript">

function checkedDisabled(cheObj,disObjId){
	var disObj = document.getElementById(disObjId);
	if(cheObj.checked==true){
		disObj.disabled='disabled';
		disObj.value='';
		if(cheObj.id='userForm.inactiveDateForm')
			document.getElementById('userForm.status').value="1";
	}else{
		disObj.disabled='';
		var ops = document.getElementById('userForm.status').options;	
		if(cheObj.id='userForm.activeDateForm')
			document.getElementById('userForm.status').value="0";		
	}
}

function validateAdd(){
	var ulogincode = document.getElementById('userForm.loginCode').value;
	if(trim(ulogincode)==''){parent.parent.parent.notifyWarn('请输入登录账号');return;}
	if (!validatePattern.validateInputZZ(ulogincode,false)){
		parent.parent.parent.notifyWarn('登录账号非法，输入只能是[汉字,数字、26个英文字母或者下划线]');
		return;
	}

	var uloginname = document.getElementById('userForm.loginName').value;
	if(trim(uloginname)==''){parent.parent.parent.notifyWarn('请输入登录名称');return;}
	if (!validatePattern.validateChinese(uloginname,false)){
		parent.parent.parent.notifyWarn('登录名称非法，输入只能是[汉字]');
		return;
	}

	var uloginpassword = document.getElementById('userForm.loginPassword').value;
	if(trim(uloginpassword)==''){parent.parent.parent.notifyWarn('请输入密码');return;}
	
	var unote = document.getElementById('userForm.note').value;
	
	userService.selectExistTUser({loginCode:ulogincode}, function(data){
		if(data == 1){
			parent.parent.parent.notifyWarn('存在相同的登录账号');
			return;
		}else{
			userService.selectExistTUser({loginName:uloginname}, function(data){
				if(data == 1){
					parent.parent.parent.notifyWarn('存在相同的登录名称');
					return;
				}else{
					layoutProgressOn(dhxLayout);
					userService.insertTUser(unitId, {loginCode:ulogincode, loginName:uloginname, loginPassword:uloginpassword, note:unote}, function(userPk){
						myUnittree.addNode(unitId, userPk + '|' + unitId, uloginname, 0, "man.gif", 0, 0, "");
						myUnittree.setUserDataAttr(userPk, "type", "user");
						myUnittree.refreshNode(unitId);
						//backAdd(userPk);
						parent.parent.parent.notifyCreater('操作成功');
						parent.addUserPageClose(userPk);
			   		});
				}
			});
		}
	});
}

function backAdd(userMainId){
	layoutProgressOn(dhxLayout);
	document.location.href = '<%=basePath%>page/system/user/user_list.jsp?unitId='+ unitId+'&willSelectedUserMainId=' + userMainId;
}


</script>
	
</html>
